import {
  Options,
  API_CHECK,
  API_FILE,
  MODEL_TYPE,
  API_MODEL,
  API_MESH,
  API_TETMESH,
  API_CELL,
  API_DEFEATURE,
  MeshCreateOptions,
  FileLoadOptions,
  FileSaveOptions,
  VIEW_MODE,
  API_VIEW,
  API_STATE,
  API_MEASURE,
  API_MASK,
  API_SELECTOR,
  API_TRIM,
  API_CONFIG,
  API_HOOKS,
  API_RENDER,
  API_GEOMETRY,
  API_MATERIAL,
  API_PROJECT,
  API_PROPERTY,
  API_LOAD_CONSTRAINTS,
  API_OUTPUTBLOCK,
  API_CARD,
  API_COLOR,
  API_COORDINATE,
  AnalysisOptions,
  MidSurfaceOptions,
  IDManagerOptions,
  RenderMode,
  API_SET,
  API_WASHER,
  WasherCreateOptions,
  WasherClearOptions,
  WasherFindOptions,
  WasherSetHoleOptions,
  API_MESHEXTRUDE2D,
  API_MESHEXTRUDE3D,
  Meshextrude2dPreviewOptions,
  Meshextrude2dCreateOptions,
  Meshextrude3dCreateOptions,
  FillHoleOptions,
  API_EDGE,
  EdgePartitionOptions,
  MidSurfaceThicknessOptions,
  API_FIND,
  API_PASTENODE,
  PastenodeApplyOptions,
  Sweep3dOptions,
  API_ROD,
  API_BEAM,
  API_FIELD,
  API_TRANSFORM,
  TransformUpdateOptions,
  API_FREEBODY,
  FreebodyApplyOptions,
  FreebodyReadFileOptions,
  FreebodyEntity,
  FreebodyFindNodesOptions,
  FreebodyEnterOptions,
  FreebodyTableDataOptions,
} from "./interface";
import { System } from "./System/System";
import { ArrayPlus, devtool, BActor, VTActor } from "cax-base";
import { Cmd_Mesh_Create } from "@/FrontProcessing/Command/Cmd_Mesh_Create";
import { Cmd_Mesh_Remesh } from "@/FrontProcessing/Command/Cmd_Mesh_Remesh";
import { Cmd_Mesh_Check } from "@/FrontProcessing/Command/Cmd_Mesh_Check";
import { Cmd_Free_Edge_Check } from "@/FrontProcessing/Command/Cmd_Free_Edge_Check";
import { Cmd_View_ModeChange } from "@/FrontProcessing/Command/Cmd_View_ModeChange";
import { MeasurementComp } from "@/FrontProcessing/Measure/MeasurementComp";
import { MeshComp } from "@/FrontProcessing/Mesh/MeshComp";
import { ModelComp } from "@/FrontProcessing/Model/ModelComp";
import { SelectorComp } from "@/FrontProcessing/Selector/SelectorComp";
import { DataComp } from "@/FrontProcessing/Data/DataComp";
import { STATE_EVENT } from "@/FrontProcessing/State/State";
import { Cmd_Delete_Mesh } from "./Command/Cmd_Delete_Mesh";
import { Cmd_Create_Cell } from "./Command/Cmd_Create_Cell";
import { SelectBoxComp } from "./Selector/SelectBoxComp";
import { Cmd_Entity_Delete } from "./Command/Cmd_Delete_Entity";
import { Cmd_Stp_Or_Bdf_File_Load } from "./Command/Cmd_Stp_File_Load";
import { Cmd_Counter_Bore } from "./Command/Cmd_Counter_Bore";
import { Cmd_Face_Fillet } from "./Command/Cmd_Face_Fillet";
import { Cmd_Analysis_Hole } from "./Command/Cmd_Analysis_Hole";
import { Cmd_Mid_Surface } from "./Command/Cmd_Mid_Surface";
import { Cmd_Mesh_Split } from "./Command/Cmd_Mesh_Split";

import { Cmd_Mesh_Detach } from "./Command/Cmd_Mesh_Detach";
import { Cmd_ID_Manager } from "./Command/Cmd_ID_Manager";
import { GyActor } from "./Actors/GyActor";
import { RemoteSystem } from "./RemoteSystem";
import { Cmd_RE_NUMBER } from "./Command/Cmd_RE_NUMBER";
import { Cmd_Tetmesh_Create } from "./Command/Cmd_Tetmesh_Create";
import { Cmd_Fill_Hole } from "./Command/Cmd_Fill_Hole";
import { Cmd_Join_Mesher } from "./Command/Cmd_Join_Mesher";
import {
  Cmd_Washer_Create,
  Cmd_Washer_Clear,
  Cmd_Washer_Find,
  Cmd_Washer_Hole,
  Cmd_Washer_Enter,
  Cmd_Washer_Leave,
  Cmd_Washer_Select,
} from "./Command/Cmd_Washer";
import {
  Cmd_Meshextrude2d_Add_Entity,
  Cmd_Meshextrude2d_Clear,
  Cmd_Meshextrude2d_Leave,
  Cmd_Meshextrude2d_Create,
  Cmd_Meshextrude2d_Preview,
  Cmd_Meshextrude2d_Update_Method,
} from "./Command/Cmd_Meshextrude2d";
import {
  Cmd_Meshextrude3d_Add_Entity,
  Cmd_Meshextrude3d_Clear,
  Cmd_Meshextrude3d_Leave,
  Cmd_Meshextrude3d_Create,
  Cmd_Meshextrude3d_Update_Method,
} from "./Command/Cmd_Meshextrude3d";
import {
  Cmd_Pastenode_Enter,
  Cmd_Pastenode_Clear,
  Cmd_Pastenode_Leave,
  Cmd_Pastenode_Apply,
  Cmd_Pastenode_Add_Nodes,
} from "./Command/Cmd_Pastenode";
import {
  Cmd_Edge_Partition,
  Cmd_Edge_Bias,
  Cmd_Edge_Ratio,
  Cmd_Edge_Leave,
} from "./Command/Cmd_Edge_Partition";
import { Cmd_Mesh_Hide_All } from "./Command/Cmd_Mesh_Hide_All";
import { Cmd_Mesh_Show_All } from "./Command/Cmd_Mesh_Show_All";
import { Cmd_Find_Load } from "./Command/Cmd_Find_Load";
import { Cmd_Mid_Surface_Thickness } from "./Command/Cmd_Mid_Surface_Thickness";
import { Cmd_Normal_Get } from "./Command/Cmd_Normal_Get";
import { Cmd_Mesh_Organized } from "./Command/Cmd_Mesh_Organized";
import { Cmd_Check_Duplicate_Elem } from "./Command/Cmd_Check_Duplicate_Elem";
import { Cmd_Cfd_Mesh_Create } from "./Command/Cmd_Cfd_Mesh_Create";
import { Cmd_Wrapper_Mesh_Create } from "./Command/Cmd_Wrapper_Mesh_Create";
import { Cmd_Mesh_Offset } from "./Command/Cmd_Mesh_Offset";
import { Cmd_Delete_Duplicate_Elem } from "./Command/Cmd_Delete_Duplicate_Elem";
import { Cmd_Mesh_Sweep3d } from "./Command/Cmd_Mesh_Sweep3d";
import {
  Cmd_Transform_Leave,
  Cmd_Transform_Update,
} from "./Command/Cmd_Transform";
import {
  Cmd_Freebody_Apply,
  Cmd_Freebody_Leave,
  Cmd_Freebody_Enter,
  Cmd_Freebody_Read_File,
  Cmd_Freebody_Sets,
  Cmd_Freebody_Find_Nodes,
  Cmd_Freebody_Update_Entities,
  Cmd_Freebody_Table_Data,
} from "./Command/Cmd_Freebody";

export class FrontProcessing {
  container: HTMLElement;
  system: System | undefined;
  remoteSystem: RemoteSystem | undefined;
  measureComp: MeasurementComp;
  meshComp: MeshComp;
  ModelComp: ModelComp;
  selectorComp: SelectorComp;
  dataComp: DataComp;
  selectBoxComp: SelectBoxComp;
  mode: RenderMode = RenderMode.WEB;

  check: API_CHECK = {
    checkD2: this.check_duplicate_elem.bind(this), // check for duplicate grid
    deleteD2: this.delete_duplicate_elem.bind(this), // delete duplicate grid
  };

  file: API_FILE = {
    stp_or_bdf_file_load: this.stp_or_bdf_file_load.bind(this),
    load: this.file_load.bind(this),
    // vtk_file_load: this.vtk_file_load.bind(this),
    // stl_file_load: this.stl_file_load.bind(this),
    // ply_file_load: this.ply_file_load.bind(this),
    save: this.file_save.bind(this),
    download: this.model_save.bind(this),
  };

  model: API_MODEL = {
    add: this.model_add.bind(this),
    remove: this.model_remove.bind(this),
    clear: this.model_clear.bind(this),
    info: this.model_info.bind(this),
    mask: this.model_mask.bind(this),
    unmask: this.model_unmask.bind(this),
  };

  defeature: API_DEFEATURE = {
    counter_bore: this.counter_bore.bind(this),
    face_fillet: this.face_fillet.bind(this),
    analysis_hole: this.analysis_hole.bind(this),
    mid_surface: this.mid_surface.bind(this),
    id_manager: this.id_manager.bind(this),
    mid_surface_thickness: this.mid_surface_thickness.bind(this),
    show_mid_surface_thickness: this.show_mid_surface_thickness.bind(this),
  };
  edge: API_EDGE = {
    edge_partition: this.edge_partition.bind(this),
    edge_mesh_bias: this.edge_mesh_bias.bind(this),
    get_ratio: this.edge_get_ratio.bind(this),
    leave: this.edge_leave.bind(this),
  };

  mesh: API_MESH = {
    create: this.mesh_create.bind(this),
    remesh: this.mesh_remesh.bind(this),
    check: this.mesh_check.bind(this),
    freeEdgeCheck: this.free_edge_check.bind(this),
    clear: this.delete_mesh.bind(this),
    merge: this.merge_mesh.bind(this),
    split: this.mesh_split.bind(this),
    hide_all: this.hide_all_mesh.bind(this),
    fillHole: this.fill_hole.bind(this),
    joinMesher: this.join_mesher.bind(this),
    show_all: this.show_all_mesh.bind(this),
    detach: this.mesh_detach.bind(this),
    quality: (type: string, threshold: number) => {
      return this.system?.mesh_quality(type, threshold);
    },
    normal_get: this.normal_get.bind(this),
    normal_show: (eids: number[], normals: number[], factor, color) => {
      this.system?.show_normal(eids, normals, factor, color);
    },
    normal_hide: () => {
      this.system?.hide_normal();
    },
    normal_align: (ids: number[]) => {
      return this.system?.normal_align(ids);
    },
    normal_reverse: (ids: number[]) => {
      return this.system?.normal_reverse(ids);
    },
    organized: this.mesh_organized.bind(this),
    cfdMeshCreate: this.cfd_mesh_create.bind(this),
    wrapperMeshCreate: this.wrapper_mesh_create.bind(this),
    offset: this.mesh_offset.bind(this),
    sweep3d: this.mesh_sweep_3d.bind(this),
    setSelectSinglePoint: this.setSelectSinglePoint.bind(this),
    getSelectSinglePoint: this.getSelectSinglePoint.bind(this),
    setSelectSingleLine: this.setSelectSingleLine.bind(this),
    getSelectSingleLine: this.getSelectSingleLine.bind(this),
  };

  washer: API_WASHER = {
    create: this.washer_create.bind(this),
    select: this.washer_select.bind(this),
    clear: this.washer_clear.bind(this),
    findpinhole: this.washer_find.bind(this),
    setHole: this.washer_hole.bind(this),
    enter: this.washer_enter.bind(this),
    leave: this.washer_leave.bind(this),
  };

  meshextrude2d: API_MESHEXTRUDE2D = {
    updateMethod: this.meshextrude2d_update_method.bind(this),
    leave: this.meshextrude2d_leave.bind(this),
    clear: this.meshextrude2d_clear.bind(this),
    addEntity: this.meshextrude2d_add_entity.bind(this),
    preview: this.meshextrude2d_preview.bind(this),
    create: this.meshextrude2d_create.bind(this),
  };

  meshextrude3d: API_MESHEXTRUDE3D = {
    updateMethod: this.meshextrude3d_update_method.bind(this),
    leave: this.meshextrude3d_leave.bind(this),
    clear: this.meshextrude3d_clear.bind(this),
    addEntity: this.meshextrude3d_add_entity.bind(this),
    create: this.meshextrude3d_create.bind(this),
  };

  pastenode: API_PASTENODE = {
    leave: this.pastenode_leave.bind(this),
    enter: this.pastenode_enter.bind(this),
    apply: this.pastenode_apply.bind(this),
    addNodes: this.pastenode_add_nodes.bind(this),
    clear: this.pastenode_clear.bind(this),
  };

  tetmesh: API_TETMESH = {
    create: this.tetmesh_create.bind(this),
  };

  cell: API_CELL = {
    create: this.cell_create.bind(this),
    re_number: this.re_number.bind(this),
  };
  geometry: API_GEOMETRY = {
    delete: this.enity_delete.bind(this),
  };

  view: API_VIEW = {
    modeChang: this.view_mode_change.bind(this),
    autoAdapt: this.view_auto_adapt.bind(this),
    setEdgeColor: this.set_edge_color.bind(this),
  };

  state: API_STATE = {
    set: this.state_set.bind(this),
    get: this.state_get.bind(this),
    clear: this.state_clear.bind(this),
    get_selected_mesh_ids: this.get_selected_mesh_ids.bind(this),
  };

  measure: API_MEASURE = {
    p2p: this.measure_p2p.bind(this),
  };

  masker: API_MASK = {
    mask: this.mask.bind(this),
    reverse: this.reverse.bind(this),
    reverseAll: this.reverseAll.bind(this),
    unmaskAll: this.unmaskAll.bind(this),
  };

  selector: API_SELECTOR = {
    selectMeshByClick: this.selector_select_mesh_by_click.bind(this),
    selectMeshByBox: this.selector_select_mesh_by_box.bind(this),
    selectMeshPointByClick: this.selector_select_mesh_point_by_click.bind(this),
    selectMeshPointByBox: this.selector_select_mesh_point_by_box.bind(this),
    clearAll: this.selector_clear_all.bind(this),
  };

  trim: API_TRIM = {
    trimFaceByLine: this.trim_face_by_line.bind(this),
    trimBodyByFace: this.trim_body_by_face.bind(this),
    trimFaceByFace: this.trim_face_by_face.bind(this),
    trimLineByNode: this.trim_line_by_node.bind(this),
  };

  config: API_CONFIG = {
    connect: this.system_connect.bind(this),
    disconnect: this.system_disconnect.bind(this),
  };

  hooks: API_HOOKS = {
    onConnected: this.hooks_on_connected.bind(this),
    onDisconnected: this.hooks_on_disconnected.bind(this),
    onEscKeyDown: this.hooks_on_esckeydown.bind(this),
  };

  render: API_RENDER = {
    render: this.system_render.bind(this),
  };

  material: API_MATERIAL = {
    getAllMaterials: this.get_all_materials.bind(this),
    createMaterial: this.create_material.bind(this),
    deleteMaterial: this.delete_material.bind(this),
    getMaterialById: this.get_material_by_id.bind(this),
    modifyMaterial: this.modify_material.bind(this),
    batchRenameMaterials: this.batch_rename_materials.bind(this),
  };
  loadConstraints: API_LOAD_CONSTRAINTS = {
    createLoadConstraints: this.create_load_constraints.bind(this),
    createBcs: this.create_bcs.bind(this),
    createDisplacement: this.create_displacement.bind(this),
    createForce: this.create_force.bind(this),
    createTemperatureSet: this.create_temperature_set.bind(this),
    deleteForceSet: this.delete_force_set.bind(this),
    deleteTemperatureSet: this.delete_temperature_set.bind(this),
    modifyForce: this.modify_force.bind(this),
    modifyDisplacemnet: this.modify_displacement.bind(this),
    modifyTemperature: this.modify_temperature.bind(this),
    setTemperature: this.set_temperature.bind(this),
    addNormal: this.add_normal.bind(this),
    deleteItem: this.delete_item.bind(this),
    getForceInfo: this.get_force_info.bind(this),
    getDisplacemnetInfo: this.get_displacement_info.bind(this),
    getAllLoadConstraints: this.get_all_load_constraints.bind(this),
  };
  property: API_PROPERTY = {
    getAllProperties: this.get_all_properties.bind(this),
    createProperty: this.create_property.bind(this),
    deleteProperty: this.delete_property.bind(this),
    getPropertyById: this.get_property_by_id.bind(this),
    modifyProperty: this.modify_property.bind(this),
    asssignProperty: this.assign_property.bind(this),
    batchRenameProperties: this.batch_rename_properties.bind(this),
  };
  set: API_SET = {
    getAllSets: this.get_all_sets.bind(this),
    createSet: this.create_set.bind(this),
    deleteSet: this.delete_set.bind(this),
    getSetById: this.get_set_by_id.bind(this),
    modifySet: this.modify_set.bind(this),
    addSet: this.add_set.bind(this),
    plotNodeSet: this.plot_nodeSet.bind(this),
    plotElementSet: this.plot_elementSet.bind(this),
  };

  outputblock: API_OUTPUTBLOCK = {
    getAllOutputblocks: this.get_all_outputblocks.bind(this),
    createOutputblock: this.create_outputblock.bind(this),
    deleteOutputblock: this.delete_outputblock.bind(this),
    getOutputblockById: this.get_outputblock_by_id.bind(this),
    modifyOutputblock: this.modify_outputblock.bind(this),
    asssignOutputblock: this.assign_outputblock.bind(this),
  };

  card: API_CARD = {
    getAllCards: this.get_all_cards.bind(this),
    createCard: this.create_card.bind(this),
    deleteCard: this.delete_card.bind(this),
    getCardById: this.get_card_by_id.bind(this),
    modifyCard: this.modify_card.bind(this),
    asssignCard: this.assign_card.bind(this),
    getElements: this.get_elements.bind(this),
  };

  coordinate: API_COORDINATE = {
    getAllCoordinates: this.get_all_coordinates.bind(this),
    createCoordinate: this.create_coordinate.bind(this),
    createNodeCoordinate: this.create_nodeCoordinate.bind(this),
    deleteCoordinate: this.delete_coordinate.bind(this),
    deleteNodeCoordinate: this.delete_nodeCoordinate.bind(this),
    getCoordinateById: this.get_coordinate_by_id.bind(this),
    modifyCoordinate: this.modify_coordinate.bind(this),
    modify_coordinatename: this.modify_coordinatename.bind(this),
    modify_nodeCoordinate: this.modify_nodeCoordinate.bind(this),
    set_nodeCoordinate: this.set_nodeCoordinate.bind(this),
    createMaterialOrientation: this.create_materialOrientation.bind(this),
    deleteMaterialOrientation: this.delete_materialOrientation.bind(this),
    modifyMaterialOrientation: this.modify_materialOrientation.bind(this),
  };

  rod: API_ROD = {
    crateRodUnit: this.create_rod_unit.bind(this),
  };
  beam: API_BEAM = {
    crateBeamByNode: this.create_beam_byNode.bind(this),
    crateBeamByLine: this.create_beam_byLine.bind(this),
    undoBeam: this.undo_beam.bind(this),
  };
  field: API_FIELD = {
    createField: this.create_field.bind(this),
    deleteField: this.delete_field.bind(this),
    modifyField: this.modify_field.bind(this),
    load2minio: this.load2minio.bind(this),
    uploadFieldFile: this.upload_field_file.bind(this),
    addFieldnodes: this.add_field_nodes.bind(this),
    showField: this.field_show.bind(this),
    clearField: this.field_clear.bind(this),
  };
  color: API_COLOR = {
    set_entity_color: this.set_entity_color.bind(this),
  };

  project: API_PROJECT = {
    save: this.project_save.bind(this),
    load: this.project_load.bind(this),
  };
  find: API_FIND = {
    findLoadByElem: this.find_load_by_elem.bind(this),
  };
  transform: API_TRANSFORM = {
    leave: this.transform_leave.bind(this),
    update: this.transform_update.bind(this),
  };
  freebody: API_FREEBODY = {
    leave: this.freebody_leave.bind(this),
    enter: this.freebody_enter.bind(this),
    read_file: this.freebody_read_file.bind(this),
    sets: this.freebody_sets.bind(this),
    update_entities: this.freebody_update_entities.bind(this),
    find_nodes: this.freebody_find_nodes.bind(this),
    apply: this.freebody_apply.bind(this),
    table_data: this.freebody_table_data.bind(this),
  };
  constructor(
    container: HTMLElement,
    selectBox: HTMLElement,
    options: Options
  ) {
    this.container = container;
    this.mode = options.renderMode || RenderMode.WEB;
    if (options.renderMode === RenderMode.WEB) {
      this.system = new System(this, container, options);
    } else {
      this.remoteSystem = new RemoteSystem(this, container, options);
    }
    this.measureComp = new MeasurementComp(this);
    this.meshComp = new MeshComp(this);
    this.ModelComp = new ModelComp(this);
    this.selectorComp = new SelectorComp(this);
    this.dataComp = new DataComp(this);
    this.selectBoxComp = new SelectBoxComp(this, selectBox, container);
  }
  private async check_duplicate_elem() {
    if (this.system) {
      return await new Cmd_Check_Duplicate_Elem(this.system, null).execute();
    }
  }
  private async delete_duplicate_elem(id: number) {
    if (this.system) {
      return await new Cmd_Delete_Duplicate_Elem(this.system, id).execute();
    }
  }
  private async stp_or_bdf_file_load(options: FileLoadOptions) {
    if (this.system) {
      return await new Cmd_Stp_Or_Bdf_File_Load(this.system, options).execute();
    }
  }

  private async counter_bore() {
    if (this.system) {
      return await new Cmd_Counter_Bore(this.system, {}).execute();
    }
  }

  private async face_fillet() {
    if (this.system) {
      return await new Cmd_Face_Fillet(this.system, {}).execute();
    }
  }

  private async analysis_hole(options: AnalysisOptions) {
    if (this.system) {
      return await new Cmd_Analysis_Hole(this.system, options).execute();
    }
  }
  private async mid_surface_thickness(options: MidSurfaceThicknessOptions) {
    if (this.system) {
      return await new Cmd_Mid_Surface_Thickness(
        this.system,
        options
      ).execute();
    }
  }
  private async show_mid_surface_thickness(options: boolean) {
    if (this.system) {
      this.system.show_mid_surface_thickness(options);
    }
  }
  private async mid_surface(options: MidSurfaceOptions) {
    if (this.system) {
      return await new Cmd_Mid_Surface(this.system, options).execute();
    }
  }
  private async edge_partition(options: EdgePartitionOptions) {
    if (this.system) {
      return await new Cmd_Edge_Partition(this.system, options).execute();
    }
  }
  private async edge_mesh_bias(options: {
    entityId: number[];
    meshCtrl: EdgePartitionOptions;
  }) {
    if (this.system) {
      return await new Cmd_Edge_Bias(this.system, options).execute();
    }
  }
  private async edge_get_ratio(options: number) {
    if (this.system) {
      return await new Cmd_Edge_Ratio(this.system, options).execute();
    }
  }
  private async edge_leave(options?: string) {
    if (this.system) {
      return await new Cmd_Edge_Leave(this.system, options).execute();
    }
  }

  private async id_manager(options: IDManagerOptions) {
    if (this.system) {
      return await new Cmd_ID_Manager(this.system, options).execute();
    }
  }

  private async file_load(
    path: string,
    type: MODEL_TYPE,
    callback?: any
  ): Promise<VTActor> {
    return await this.system?.file_load(path, type, callback);
  }

  // private async vtk_file_load(path: string): Promise<boolean> {
  //   return await this.system?.vtk_file_load(path);

  // private async stl_file_load(path: string): Promise<boolean> {
  //   return await this.system?.stl_file_load(path);
  // }
  // private async ply_file_load(path: string: Promise<boolean> {
  //   return await this.system?.ply_file_load(path);
  // }
  private async file_save(param: FileSaveOptions): Promise<string> {
    if (this.mode === RenderMode.WEB && this.system) {
      return await this.system?.file_save(param);
    } else {
      return await Promise.resolve("");
    }
  }
  // 下载原始文件
  private async model_save(filename: string, toType: string): Promise<string> {
    if (this.mode === RenderMode.WEB && this.system) {
      return await this.system?.model_save(filename, toType);
    } else {
      return await Promise.resolve("");
    }
  }
  private model_add(actor: BActor) {
    this.system?.model_add(actor);
  }

  private model_remove(actor: BActor) {
    this.system?.model_remove(actor);
  }

  private model_clear() {
    this.system?.model_clear();
  }

  private model_mask(partId: number) {
    this.system?.model_mask(partId);
  }

  private model_unmask(partId: number) {
    this.system?.model_unmask(partId);
  }

  private mesh_create(options: MeshCreateOptions): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Mesh_Create(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private cfd_mesh_create(options: any): Promise<any> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Cfd_Mesh_Create(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private wrapper_mesh_create(options: any): Promise<any> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Wrapper_Mesh_Create(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private mesh_offset(options: any): Promise<any> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Mesh_Offset(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }

  private tetmesh_create(options: MeshCreateOptions): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Tetmesh_Create(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }

  private enity_delete(value: number): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Entity_Delete(this.system, value).execute();
    } else {
      return Promise.resolve(false);
    }
  }

  private mesh_remesh(options: MeshCreateOptions): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Mesh_Remesh(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }

  private mesh_check(options: MeshCreateOptions): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Mesh_Check(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private free_edge_check(options: MeshCreateOptions): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Free_Edge_Check(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private delete_mesh(): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Delete_Mesh(this.system, {}).execute();
    } else {
      return Promise.resolve(false);
    }
  }

  private merge_mesh(
    partId: number,
    cellId1: number,
    cellId2: number
  ): Promise<any> {
    return new Promise((resolve) => {
      if (this.system) {
        this.system.merge_mesh(partId, cellId1, cellId2).then((result) => {
          resolve(result);
        });
      }
    });
  }

  private cell_create(options: any): Promise<any> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Create_Cell(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private re_number(options: any): Promise<any> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_RE_NUMBER(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }

  private view_mode_change(mode: VIEW_MODE) {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_View_ModeChange(this.system, { mode }).execute();
    }
  }

  private async state_set(key: string, value: any) {
    try {
      this.system?.set_state(key, value);
      return true;
    } catch (error) {
      console.error("Failed to set state:", error);
      return false;
    }
  }

  private state_get(key: string) {
    return this.system?.get_state(key);
  }

  private measure_p2p(
    id1: number,
    id2: number,
    partId1: number,
    partId2: number
  ) {
    return this.system?.measure_p2p(id1, id2, partId1, partId2);
  }

  private mask() {
    return this.system?.mask();
  }

  private reverseAll() {
    return this.system?.reverseAll();
  }

  private reverse() {
    return this.system?.reverse();
  }

  private unmaskAll() {
    return this.system?.unmaskAll();
  }

  private model_info() {
    const bomInfo = this.dataComp.getBomData();
    if (bomInfo.length > 1) {
      return Promise.resolve(bomInfo);
    }
    return this.system?.model_info();
  }

  private selector_select_mesh_by_click(id: number) {
    return this.system?.selector_select_mesh_by_click(id);
  }

  private selector_select_mesh_by_box(id: number) {
    return this.system?.selector_select_mesh_by_box(id);
  }

  private selector_select_mesh_point_by_click(id: number) {
    return this.system?.selector_select_mesh_point_by_click(id);
  }

  private selector_select_mesh_point_by_box(id: number) {
    return this.system?.selector_select_mesh_point_by_box(id);
  }

  private selector_clear_all() {
    return this.system?.clear_all_selected();
  }

  private trim_face_by_line(options: any) {
    return this.system?.trim_face_by_line(options); // 用边（特征线）切割面
  }

  private trim_body_by_face(options: any) {
    return this.system?.trim_body_by_face(options); // 固体分割（面）
  }
  private trim_face_by_face(options: any) {
    return this.system?.trim_face_by_face(options); // 面与面相互切割
  }
  private trim_line_by_node(options: any) {
    return this.system?.trim_line_by_node(options); // 点到线的切割（面）
  }

  private system_connect(name: string, url: string, path?: string) {
    this.system?.connect(name, url, path);
  }

  private system_disconnect() {
    this.system?.disconnect();
  }

  private hooks_on_connected(callback: () => void) {
    this.system?.state.sub(STATE_EVENT.CONNECT, callback);
  }

  private hooks_on_disconnected(callback: () => void) {
    this.system?.state.sub(STATE_EVENT.DISCONNECT, callback);
  }
  private hooks_on_esckeydown(callback: () => void) {
    this.system?.state.sub(STATE_EVENT.ESCKEYDOWN, callback);
  }

  private view_auto_adapt() {
    return this.system?.view_auto_adapt();
  }
  private set_edge_color(v: boolean) {
    return this.system?.set_edge_color(v);
  }

  private system_render() {
    this.system?.app.render();
  }

  private get_all_materials() {
    return this.system?.get_all_materials();
  }

  private create_material(values: any) {
    return this.system?.create_material(values);
  }

  private batch_rename_materials(prefix: any, suffix: any, materials: any) {
    return this.system?.batch_rename_materials(prefix, suffix, materials);
  }
  private create_load_constraints(values: any) {
    return this.system?.create_load_constraints(values);
  }

  private create_bcs(values: any) {
    return this.system?.create_bcs(values);
  }

  private create_force(values: any) {
    return this.system?.create_force(values);
  }

  private create_temperature_set(values: any) {
    return this.system?.create_temperature_set(values);
  }

  private delete_temperature_set(id: number) {
    return this.system?.delete_temperature_set(id);
  }

  private delete_force_set(values: any) {
    return this.system?.delete_force_set(values);
  }

  private delete_item(values: any) {
    return this.system?.delete_item(values);
  }

  private modify_force(values: any) {
    return this.system?.modify_force(values);
  }

  private modify_displacement(values: any) {
    return this.system?.modify_displacement(values);
  }

  private modify_temperature(id: number, values: any) {
    return this.system?.modify_temperature(id, values);
  }

  private set_temperature(node: any, values: any) {
    return this.system?.set_temperature(node, values);
  }
  private create_displacement(values: any) {
    return this.system?.create_displacement(values);
  }

  private add_normal(values: any) {
    return this.system?.add_normal(values);
  }

  private get_force_info(id: any) {
    return this.system?.get_force_info(id);
  }

  private get_displacement_info(id: any) {
    return this.system?.get_displacement_info(id);
  }

  private get_all_load_constraints() {
    return this.system?.get_all_load_constraints();
  }

  private delete_material(id: number) {
    return this.system?.delete_material(id);
  }

  private get_material_by_id(id: number) {
    return this.system?.get_material_by_id(id);
  }

  private modify_material(id: number, values: any) {
    return this.system?.modify_material(id, values);
  }

  private get_all_sets() {
    return this.system?.get_all_sets();
  }

  private create_set(values: any) {
    return this.system?.create_set(values);
  }

  private delete_set(id: number) {
    return this.system?.delete_set(id);
  }

  private get_set_by_id(id: number) {
    return this.system?.get_set_by_id(id);
  }

  private modify_set(id: number, values: any) {
    return this.system?.modify_set(id, values);
  }

  private add_set(values: any, sets: any) {
    return this.system?.add_set(values, sets);
  }

  private plot_nodeSet() {
    return this.system?.plot_nodeSet();
  }

  private plot_elementSet() {
    return this.system?.plot_elementSet();
  }
  private get_all_properties() {
    return this.system?.get_all_properties();
  }

  private create_property(values: any) {
    return this.system?.create_property(values);
  }

  private delete_property(id: number) {
    return this.system?.delete_property(id);
  }

  private get_property_by_id(id: number) {
    return this.system?.get_property_by_id(id);
  }

  private modify_property(id: number, values: any) {
    return this.system?.modify_property(id, values);
  }

  private assign_property(entity_ids: number[], prop_id: number) {
    return this.system?.assign_property(entity_ids, prop_id);
  }

  private batch_rename_properties(prefix: any, suffix: any, properties: any) {
    return this.system?.batch_rename_properties(prefix, suffix, properties);
  }

  private get_all_outputblocks() {
    return this.system?.get_all_outputblocks();
  }

  private create_outputblock(values: any) {
    return this.system?.create_outputblock(values);
  }

  private delete_outputblock(id: number) {
    return this.system?.delete_outputblock(id);
  }

  private get_outputblock_by_id(id: number) {
    return this.system?.get_outputblock_by_id(id);
  }

  private modify_outputblock(id: number, values: any) {
    return this.system?.modify_outputblock(id, values);
  }

  private assign_outputblock(entity_ids: number[], prop_id: number) {
    return this.system?.assign_outputblock(entity_ids, prop_id);
  }

  private get_all_cards() {
    return this.system?.get_all_cards();
  }

  private get_elements() {
    return this.system?.get_elements();
  }

  private create_card(values: any) {
    return this.system?.create_card(values);
  }

  private delete_card(id: number) {
    return this.system?.delete_card(id);
  }

  private get_card_by_id(id: number) {
    return this.system?.get_card_by_id(id);
  }

  private modify_card(id: number, values: any) {
    return this.system?.modify_card(id, values);
  }

  private assign_card(entity_ids: number[], prop_id: number) {
    return this.system?.assign_card(entity_ids, prop_id);
  }
  private get_all_coordinates() {
    return this.system?.get_all_coordinates();
  }

  private create_coordinate(values: any) {
    return this.system?.create_coordinate(values);
  }
  private create_materialOrientation(values: any) {
    return this.system?.create_materialOrientation(values);
  }
  private create_nodeCoordinate(values: any) {
    return this.system?.create_nodeCoordinate(values);
  }
  private delete_coordinate(id: number) {
    return this.system?.delete_coordinate(id);
  }
  private delete_nodeCoordinate(id: number) {
    return this.system?.delete_nodeCoordinate(id);
  }
  private set_nodeCoordinate(node: any, values: any) {
    return this.system?.set_nodeCoordinate(node, values);
  }
  private delete_materialOrientation(id: number) {
    return this.system?.delete_materialOrientation(id);
  }
  private get_coordinate_by_id(id: number) {
    return this.system?.get_coordinate_by_id(id);
  }
  private modify_coordinate(nodes_info: any, name: string, setName: string) {
    return this.system?.modify_coordinate(nodes_info, name, setName);
  }
  private modify_coordinatename(id: number, values: any) {
    return this.system?.modify_coordinatename(id, values);
  }
  private modify_nodeCoordinate(id: number, values: any) {
    return this.system?.modify_nodeCoordinate(id, values);
  }
  private modify_materialOrientation(id: number, values: any) {
    return this.system?.modify_materialOrientation(id, values);
  }

  private create_rod_unit(rodNode1: any, rodNode2: any, rodUnitType: any) {
    return this.system?.create_rod_unit(rodNode1, rodNode2, rodUnitType);
  }
  private create_beam_byNode(leftNode: any, rightNode: any, values: any) {
    return this.system?.create_beam_byNode(leftNode, rightNode, values);
  }
  private create_beam_byLine(values: any) {
    return this.system?.create_beam_byLine(values);
  }
  private undo_beam(values: any) {
    return this.system?.undo_beam(values);
  }
  private create_field(values: any) {
    return this.system?.create_field(values);
  }
  private delete_field(id: number) {
    return this.system?.delete_field(id);
  }
  private modify_field(id: number, values: any) {
    return this.system?.modify_field(id, values);
  }
  private add_field_nodes(nodes: any, values: any) {
    return this.system?.add_field_nodes(nodes, values);
  }
  private field_show() {
    return this.system?.changeFaceColor();
  }
  private field_clear() {
    return this.system?.clearFaceColor();
  }

  private async load2minio(filename: string, arrayBuffer: any): Promise<any> {
    return (
      this.system?.load2minio(filename, arrayBuffer) ??
      Promise.resolve(undefined)
    );
  }
  private async upload_field_file(
    fileName: string,
    name: any,
    id: any
  ): Promise<any> {
    if (this.mode === RenderMode.WEB && this.system) {
      return await this.system?.upload_field_file(fileName, name, id);
    } else {
      return await Promise.resolve("");
    }
  }
  private set_entity_color(entity_id: number, rgb: number[]) {
    this.system?.set_entity_color(entity_id, rgb);
  }

  private project_save() {
    return this.system?.project_save();
  }

  private project_load(path: string) {
    return this.system?.project_load(path);
  }

  private state_clear() {
    return this.system?.state_clear();
  }

  public clear() {
    this.system?.clearAll();
  }

  public selectFace(partId: any, faceId: any, pickedCellId: any) {
    const actorList = this.system?.app.actorList as ArrayPlus<GyActor>;
    const back = this.selectorComp.getTriangleIdsByFaceId(
      actorList,
      partId,
      faceId
    );
    this.system?.selectFace(back, pickedCellId);
    this.system?.app.render();
  }

  public setSelectEdgeByEdgeId(edgeId: number, faceId: number, partId = 1) {
    // * 从线的id反查线的index
    this.system?.app.actorList.foreach((actor: any) => {
      if (actor instanceof VTActor) {
        if ((actor as GyActor).partId === partId) {
          const index = actor.outlines?.edgeData.edgeIds?.findIndex(
            (id: number) => id === edgeId
          );
          if (index === -1 || !index) {
            devtool.error("查询不到轮廓线的ID");
          } else {
            const cellIndexArr = [];
            const edgeLineNums = actor.outlines?.edgeData?.edgeLineNums;
            if (!edgeLineNums) return;
            let start,
              end = 0;

            if (index === 0) {
              start = 0;
              end = edgeLineNums[0];
            } else {
              start = edgeLineNums[index - 1];
              end = edgeLineNums[index];
            }

            for (let i = start; i < end; i++) {
              cellIndexArr.push(i);
            }

            this.system?.setSelectEdgeByEdgeId(
              index,
              edgeId,
              faceId,
              partId,
              cellIndexArr
            );
            this.system?.app.render();
          }
        }
      }
    });
  }

  public registerNormalRightClick() {
    this.system?.registerNormalRightClick();
  }

  public unregisterNormalRightClick() {
    this.system?.unregisterNormalRightClick();
  }

  public registerSelectPointRightClick() {
    this.system?.registerSelectPointRightClick();
  }

  public registerSelectSinglePointRightClick() {
    this.system?.registerSelectSinglePointRightClick();
  }

  public registerSelectSingleLineRightClick() {
    this.system?.registerSelectSingleLineRightClick();
  }

  public unregisterSelectPointRightClick() {
    this.system?.unregisterSelectPointRightClick();
  }

  public unregisterSelectSinglePointRightClick() {
    this.system?.unregisterSelectSinglePointRightClick();
  }

  public unregisterSelectSingleLineRightClick() {
    this.system?.unregisterSelectSingleLineRightClick();
  }
  public setSelectSinglePoint(coordinate: number[], pointActor: any) {
    this.system?.setSelectSinglePoint(coordinate, pointActor);
  }
  public getSelectSinglePoint() {
    return this.system?.getSelectedSinglePoint();
  }
  public setSelectSingleLine(lineCoordinate: number[], lineActor: any) {
    this.system?.setSelectSingleLine(lineCoordinate, lineActor);
  }
  public getSelectSingleLine() {
    return this.system?.getSelectedSingleLine();
  }
  private mesh_split(options: any): Promise<any> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Mesh_Split(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private mesh_detach(options: any): Promise<any> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Mesh_Detach(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private mesh_organized(options: any): Promise<any> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Mesh_Organized(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }

  private fill_hole(options: FillHoleOptions): Promise<any> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Fill_Hole(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private join_mesher(options: any): Promise<any> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Join_Mesher(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private washer_select(options?: any): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Washer_Select(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private washer_create(options: WasherCreateOptions): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Washer_Create(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private washer_clear(options?: WasherClearOptions): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Washer_Clear(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private washer_find(options: WasherFindOptions): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Washer_Find(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private washer_hole(options: WasherSetHoleOptions): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Washer_Hole(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private washer_enter(options?: any): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Washer_Enter(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private washer_leave(options?: any): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Washer_Leave(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private meshextrude2d_update_method(options?: string): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Meshextrude2d_Update_Method(
        this.system,
        options
      ).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private meshextrude2d_leave(options?: string): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Meshextrude2d_Leave(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private meshextrude2d_clear(options?: string): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Meshextrude2d_Clear(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private meshextrude2d_add_entity(options?: string): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Meshextrude2d_Add_Entity(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private meshextrude2d_preview(
    options: Meshextrude2dPreviewOptions
  ): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Meshextrude2d_Preview(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private meshextrude2d_create(
    options: Meshextrude2dCreateOptions
  ): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Meshextrude2d_Create(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }

  private hide_all_mesh() {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Mesh_Hide_All(this.system, null).execute();
    }
  }
  private meshextrude3d_update_method(options?: string): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Meshextrude3d_Update_Method(
        this.system,
        options
      ).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private meshextrude3d_clear(options?: string): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Meshextrude3d_Clear(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private meshextrude3d_add_entity(options?: string): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Meshextrude3d_Add_Entity(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private meshextrude3d_create(
    options: Meshextrude3dCreateOptions
  ): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Meshextrude3d_Create(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private meshextrude3d_leave(options?: string): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Meshextrude3d_Leave(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private pastenode_enter(options?: string): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Pastenode_Enter(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private pastenode_clear(options?: string): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Pastenode_Clear(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private pastenode_add_nodes(
    name: string,
    pointIds?: any[]
  ): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Pastenode_Add_Nodes(this.system, {
        name,
        pointIds,
      }).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private pastenode_apply(option: PastenodeApplyOptions): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Pastenode_Apply(this.system, option).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private pastenode_leave(option?: string): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Pastenode_Leave(this.system, option).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private mesh_sweep_3d(option: Sweep3dOptions): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Mesh_Sweep3d(this.system, option).execute();
    } else {
      return Promise.resolve(false);
    }
  }

  private show_all_mesh() {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Mesh_Show_All(this.system, null).execute();
    }
  }
  private find_load_by_elem() {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Find_Load(this.system, null).execute();
    } else {
      return Promise.resolve(false);
    }
  }

  private normal_get(ids: number[]) {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Normal_Get(this.system, ids).execute();
    }
    return Promise.resolve(false);
  }

  private get_selected_mesh_ids() {
    if (this.mode === RenderMode.WEB && this.system) {
      return this.system.state.getSelectedMeshIds();
    }
    return [];
  }

  private transform_leave(option: string): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Transform_Leave(this.system, option).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private transform_update(options: TransformUpdateOptions): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Transform_Update(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }

  private freebody_leave(option?: string): Promise<boolean> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Freebody_Leave(this.system, option).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private freebody_enter(options: FreebodyEnterOptions): Promise<any> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Freebody_Enter(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private freebody_read_file(options: FreebodyReadFileOptions): Promise<any> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Freebody_Read_File(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private freebody_sets(): Promise<any> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Freebody_Sets(this.system, null).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private freebody_update_entities(options: FreebodyEntity[]): Promise<any> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Freebody_Update_Entities(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private freebody_find_nodes(options: FreebodyFindNodesOptions): Promise<any> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Freebody_Find_Nodes(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private freebody_apply(options: FreebodyApplyOptions): Promise<any> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Freebody_Apply(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }
  private freebody_table_data(options: FreebodyTableDataOptions): Promise<any> {
    if (this.mode === RenderMode.WEB && this.system) {
      return new Cmd_Freebody_Table_Data(this.system, options).execute();
    } else {
      return Promise.resolve(false);
    }
  }

  runScript(script: string) {
    if (this.mode === RenderMode.WEB && this.system) {
      return this.system.connector.script_run(script);
    } else {
      return Promise.resolve(false);
    }
  }
}
